package com.mojo.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Spring事务传播行为示例
 *
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2022, 广州九尾信息科技有限公司
 * @date 2022/3/8 15:46
 */
@Component
public class UserPropagation extends UserDaoImpl_Annotation {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private UserDaoImpl_Annotation userDaoImpl_annotation;
    //隔离级别
    @Transactional(rollbackFor = Exception.class,
            isolation = Isolation.REPEATABLE_READ
            //传播行为
            , propagation = Propagation.REQUIRED,
            timeout = 30)
    @Override
    public int update(Long id) {
        int update = 0;
        String sql = "update backstage_user set nickname= ? where id=?";
        Object[] objects = {"牧哲111", 1};
        try {
            userDaoImpl_annotation.updateById(1L);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e);
        }
        update = jdbcTemplate.update(sql, objects);
        String insert = "insert into backstage_role (name,description) values(?,?)";
        Object[] objects1 = {"超管111","1111"};
        int insert1 = jdbcTemplate.update(insert, objects1);
        //int n = 1 / 0;


        return update;
    }
}
